package com.example.shengyin.service;

import com.example.shengyin.dao.SubjectMapper;
import com.example.shengyin.entity.Page;
import com.example.shengyin.entity.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * SubjectService业务层处理
 * 
 * @author gyy
 * @date 2023-07-29
 */
@Service
//@Transactional(readOnly = true, timeout = -1, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@Cacheable(cacheNames = "subject",keyGenerator = "root")
public class SubjectService
{

    @Autowired
    private SubjectMapper dao;

    public Subject select(Long id)
    {
        return dao.select(id);
    }

    public List<Subject> list(Page page,String cname,String poster)
    {
        return dao.list((page.getPage()-1)*page.getLimit(),page.getLimit(),cname,poster);
    }
    public int count(String cname,String poster)
    {
       return dao.count(cname,poster);
    }
    @CacheEvict(allEntries = true,cacheNames = "subject")
    public List<Subject> list2(String cname)
    {
        return dao.list2(cname);
    }
    @CacheEvict(allEntries = true,cacheNames = "subject")
    public List<Subject> list3(Page page)
    {
        return dao.list3((page.getPage()-1)*page.getLimit(),page.getLimit());
    }
    public int count2(String cname)
    {
        return dao.count2(cname);
    }

    public int count3(String cname)
    {
        return dao.count3(cname);
    }
    @CacheEvict(allEntries = true,cacheNames = "subject")
    public int insert(Subject dSubject)
    {
        return dao.insert(dSubject);
    }
    @CacheEvict(allEntries = true,cacheNames = "subject")
    public int update(Subject dSubject)
    {
        return dao.update(dSubject);
    }
    @CacheEvict(allEntries = true,cacheNames = "subject")
    public int deleteByIds(String ids)
    {
        return dao.deleteByIds(ids);
    }
    @CacheEvict(allEntries = true,cacheNames = "subject")
    public int delete(int id)
    {
        return dao.delete(id);
    }
    public List<String> findCname(){
        return dao.findCname();
    }
    public List<Subject> page1(String cname){
        return dao.page1(cname);
    }
    public List<Subject> getAll(long id){
        return dao.getAll(id);
    }

}
